/*
 *  TCPconnections.h
 */

//------------------------------------------------------------------------------
 int  create_tcp_client_socket(int port, char ip[STRING_SIZE])
 {
	 struct sockaddr_in server_addr;
	 int e=-1;
	 int sid;
	 sid=socket(AF_INET,SOCK_STREAM,0);
	 
	 server_addr.sin_family=AF_INET;
	 server_addr.sin_addr.s_addr=inet_addr(ip);
	 server_addr.sin_port=htons(port);
	 fprintf(","connectint to port: %d.\n",ntohs(server_addr.sin_port));
	 
	while(e<0)
	  {
		  e=connect(sid,(struct sockaddr*)&server_addr,sizeof(struct sockaddr));
		  if(e>=0)
			  break;
		  close(sid);
		  sleep(1);
		  sid=socket(AF_INET,SOCK_STREAM,0);
	  }
	 
	return sid;
}
